﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boggle
{
    public partial class Game
    {
        private class EndedState : IGameState
        {
            private readonly Game game;

            public EndedState(Game game)
            {
                if (game == null)
                {
                    throw new ArgumentNullException("game");
                }

                this.game = game;
            }

            public void Initialize()
            {
                game.currentTime = game.expectedEndTime;
                game.UpdateSecondsLeft();
            }

            public void Start(DateTime currentTime)
            {
                throw new InvalidOperationException("Cannot start a game that is ended");
            }

            public Boolean Next(DateTime currentTime)
            {
                return !game.CompleteLookups();
            }

            public void SubmitWord()
            {
                throw new InvalidOperationException("Cannot submit a word after the game has ended");
            }

            public void EndGame()
            {
                throw new InvalidOperationException("Cannot end a game that has already ended");
            }

            public void NewGame()
            {
                if (game.wordLookupTasks.Count > 0)
                {
                    throw new InvalidOperationException("Cannot start a new game before all pending definition lookups have completed");
                }

                game.SetState(GameState.Setup);
            }

            public IBoggleDictionary Dictionary
            {
                get { return game.dict; }
                set { throw new InvalidOperationException("Cannot set Dictionary while the game is ending"); }
            }
        }
    }
}
